#include <windows.h>

#if defined(_WIN64)
#define titlu "wapp 64b - costelsoft.ro"
#else
#define titlu "wapp 32b - costelsoft.ro"
#endif

HINSTANCE appI; HWND appW;

//
LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM wP, LPARAM lP) 
{	
   switch(m)
   {
   case WM_CLOSE:			
      DestroyWindow(h); PostQuitMessage(0);
      break;
   }

   return DefWindowProcA(h, m, wP, lP);
}

//
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR lCL, int nCS)
{

   WNDCLASSEXA wc;
   memset(&wc, 0, sizeof(wc));
   wc.hInstance = appI = hI;
   wc.lpszClassName = "appW";
   wc.lpfnWndProc = WndProc;
   wc.cbSize = sizeof(wc);
   wc.hIcon = LoadIcon(hI, MAKEINTRESOURCE(1));
   wc.hIconSm = (HICON)LoadImage(hI, MAKEINTRESOURCE(1), IMAGE_ICON, 16, 16, 0);
   wc.hbrBackground = (HBRUSH)COLOR_MENU;
   wc.hCursor = LoadCursorA(0, IDC_ARROW);

   if(!RegisterClassExA(&wc))
   { 
      MessageBoxA(0, "RegisterClassEx error!", titlu, 0);
      ExitProcess(0);
   }

   struct { int x, y, w, h; } sett;
   sett.x = 333; sett.y = 222; sett.w = 333; sett.h = 333;

   appW = CreateWindowExA(0, "appW", titlu, WS_OVERLAPPEDWINDOW|WS_VISIBLE, sett.x, sett.y, sett.w, sett.h, HWND_DESKTOP, 0, hI, 0);

   if(!appW)
   {
      MessageBoxA(0, "appW CreateWindowEx error!", titlu, 0);
      ExitProcess(0);
   }

   ShowWindow(appW, 1); UpdateWindow(appW);

   MSG msg;
   while(GetMessage(&msg,0,0,0))
   {
      TranslateMessage(&msg);
      DispatchMessageA(&msg);
   }

   UnregisterClassA("appW", hI);

   return (int)msg.wParam;

}
